package org.example.aaaatest.a1;

import com.google.common.collect.Maps;
import org.apache.commons.lang3.StringUtils;

import java.util.HashMap;

/**
 * 货币类型枚举
 * <p>
 * https://aliyuque.antfin.com/shunzhao.hsz/yiig4f/ekdyvc
 * 多币种展示工具 MoneyFormatter
 */
public enum CurrencyEnum {

    /**
     * 人民币
     */
    CNY("CNY", "156", "元", 2, "￥"),
    
    /**
     * 港元
     */
    HKD("HKD", "344", "港元", 2, "HK$"),

    /**
     * 澳门元
     */
    MOP("MOP", "446", "澳门元", 2, "MOP$"),
    
    /**
     * 美元
     */
    USD("USD", "840", "美元", 2, "$"),

    /**
     * 韩元
     */
    KRW("KRW", "410", "韩元", 2, "₩"),

    /**
     * 菲律宾
     */
    PHP("PHP", "608", "菲律宾比索", 2, "₱"),

    /**
     * 马来西亚
     */
    MYR("MYR", "458", "林吉特", 2, "RM"),

    /**
     * 泰铢
     */
    THB("THB", "840", "泰铢", 2, "฿"),
    /**
     * 新加坡
     */
    SGD("SGD", "702", "新加坡元", 2, "S$"),

    /**
     * 印度尼西亚
     */
    IDR("IDR", "360", "印尼盾", 2, "Rp"),

    /**
     * 越南
     */
    VND("VND", "704", "越南盾", 2, "₫"),
    /**
     * 日本
     */
    JPY("JPY", "392", "日元", 0, "JPY"),

    ;

    /**
     * 标准币种值
     */
    private final String currencyCode;
    /**
     * 币种代码
     */
    private final String currency;

    /**
     * 中文描述
     */
    private final String desc;


    /**
     * 货币符号
     */
    private final String currencyLabel;


    /**
     * 最小货币单位和默认货币单位转换精度
     */
    private final Integer defaultFractionDigits;



    /**
     * 标准币种值,货币枚举对象映射集合
     */
    private final static HashMap<String, CurrencyEnum> currencyEnumCodeMap = Maps.newHashMap();
    /**
     * 币种代码,货币枚举对象映射集合
     */
    private final static HashMap<String, CurrencyEnum> currencyEnumMap = Maps.newHashMap();

    static {
        for (CurrencyEnum currencyEnum : CurrencyEnum.values()) {
            currencyEnumCodeMap.put(currencyEnum.getCurrencyCode(), currencyEnum);
            currencyEnumMap.put(currencyEnum.getCurrency(), currencyEnum);
        }
    }

    /**
     * 通过标准币种值获取货币枚举对象
     *
     * @param currencyCode
     * @return
     */
    public static CurrencyEnum getEnumByCurrencyCode(String currencyCode) {
        if (StringUtils.isBlank(currencyCode)) {
            return CNY;
        }
        return currencyEnumCodeMap.get(currencyCode);
    }

    /**
     * 通过币种代码（订单信息存储的货币单位：HKD）获取枚举对象
     *
     * @param currency
     * @return
     */
    public static CurrencyEnum getEnumByCurrency(String currency) {
        if (StringUtils.isBlank(currency)) {
            return CNY;
        }
        return currencyEnumMap.get(currency);
    }

    CurrencyEnum(String currency, String                                                                                                                                                                                                            currencyCode, String desc, Integer defaultFractionDigits, String currencyLabel) {
        this.currency = currency;
        this.currencyCode = currencyCode;
        this.desc = desc;
        this.defaultFractionDigits = defaultFractionDigits;
        this.currencyLabel = currencyLabel;
    }


    public String getCurrency() {
        return currency;
    }


    public String getDesc() {
        return desc;
    }


    public Integer getDefaultFractionDigits() {
        return defaultFractionDigits;
    }


    public String getCurrencyCode() {
        return currencyCode;
    }


    public String getCurrencyLabel() {
        return currencyLabel;
    }


}
